<template>
  <div class="app-container">
  <!-- 录取学生 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <!-- <el-form-item label="学籍号" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入学籍号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="登陆密码" prop="password">
        <el-input
          v-model="queryParams.password"
          placeholder="请输入登陆密码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="学生姓名" prop="name" style="width:20% ;">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入学生姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="出生日期" prop="birthday">
        <el-date-picker clearable
          v-model="queryParams.birthday"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择出生日期">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="身份证号" prop="idcard" style="width:20% ;">
        <el-input
          v-model="queryParams.idcard"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="毕业学校标识码" prop="graduateCode">
        <el-input
          v-model="queryParams.graduateCode"
          placeholder="请输入毕业学校标识码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="志愿区县" prop="streetId" style="width:20% ;">

        <el-select v-model="queryParams.streetId" placeholder="请选择志愿区县" @change="selectSchoolArea">
          <el-option
            v-for="item in areaOptions"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="填报志愿学校" prop="enrolCode" style="width:20% ;">
        <el-input
          v-model="queryParams.enrolCode"
          placeholder="请输入填报志愿学校"
          clearable
          @keyup.enter.native="handleQuery"
        />
        <el-select v-model="queryParams.enrolCode" placeholder="请选择志愿区县">
          <el-option
            v-for="item in schoolAreaOptions"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item label="区域">
        <el-select v-model="queryParams.areaId" clearable placeholder="请选择户口所在地" @change="selectSchoolArea">
          <el-option
            v-for="item in areaOptions"
            :key="item.coded"
            :label="item.name"
            :value="item.coded"
            @keyup.enter.native="handleQuery"
            >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="志愿学校" prop="coded">
        <el-select v-model="queryParams.enrolCode" clearable placeholder="先选择区域">
            <el-option
              v-for="item in schoolAreaOptions"
              :key="item.coded"
              :label="item.name"
              :value="item.coded"
              @keyup.enter.native="handleQuery"
              >
            </el-option>
          </el-select>
      </el-form-item>
      <el-form-item >
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" >搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="studentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="所属区县" align="center" prop="areaIdStr" />

      <el-table-column label="学校名称" align="center" prop="name"/>
      <el-table-column label="学校编号" align="center" prop="coded" />
      <!-- <el-table-column label="志愿学校类型" align="center" prop="enrolType" /> -->
      <el-table-column label="总人数" align="center" prop="allNum" />
      <el-table-column label="已报名人数" align="center" prop="enrollNum" />

      <el-table-column label="已审核人数" align="center" prop="checkNum" />

      <el-table-column label="已录取人数" align="center" prop="acceptNum" />

      <el-table-column label="计划录取人数" align="center" prop="plan" />
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改学生对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules"  :inline="true" label-position="top" size="small" style="padding-left:50px;">
        <el-form-item label="学生姓名" prop="name" style="width: 22%;">
          <el-input v-model="form.name" placeholder="请输入学生姓名" />
        </el-form-item>
        <el-form-item label="出生日期" prop="birthday" style="width: 22%;">
          <el-date-picker clearable
            v-model="form.birthday"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="身份证" prop="idcard" style="width: 22%;">
          <el-input v-model="form.idcard" placeholder="请输入身份证" />
        </el-form-item>
        <el-form-item label="学籍号" prop="code" style="width: 22%;">
          <el-input v-model="form.code" placeholder="请输入学籍号" />
        </el-form-item>
        <el-form-item label="登陆密码" prop="password" style="width: 22%;">
          <el-input v-model="form.password" placeholder="请输入登陆密码" />
        </el-form-item>

        <el-form-item label="户口所在地" prop="streetId" style="width: 22%;">
          <el-select v-model="form.streetId" clearable placeholder="请选择学校区域">
            <el-option
              v-for="item in areaOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
              @keyup.enter.native="handleQuery"
              >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="户籍详细地址" prop="hukouAddress" style="width: 22%;">
          <el-input v-model="form.hukouAddress" placeholder="请输入户籍详细地址" />
        </el-form-item>
        <el-form-item label="街道详情" prop="streetStr" style="width: 22%;">
          <el-input v-model="form.streetStr" placeholder="请输入街道详情" />
        </el-form-item>
        <el-form-item label="区域" prop="areaId" style="width: 22%;">
          <el-select v-model="form.areaId" clearable placeholder="请选择学校区域" @change="selectSchoolArea">
            <el-option
              v-for="item in areaOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
              @keyup.enter.native="handleQuery"
              >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="填报志愿学校" prop="enrolCode" style="width: 22%;">
          <el-select v-model="form.enrolCode" clearable placeholder="请选择学校">
            <el-option
              v-for="item in schoolAreaOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
              @keyup.enter.native="handleQuery"
              >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="毕业学校标识码" prop="graduateCode" style="width: 22%;">
          <el-input v-model="form.graduateCode" placeholder="请输入毕业学校标识码" />
        </el-form-item>
        <el-form-item label="学校班级" prop="schoolClass" style="width: 22%;">
          <el-input v-model="form.schoolClass" placeholder="请输入学校班级" />
        </el-form-item>
        <el-form-item label="报名时间" prop="applyTime" style="width: 22%;">
          <el-date-picker clearable
            v-model="form.applyTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择报名时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="房产地址" prop="propertyAddress" style="width: 22%;">
          <el-input v-model="form.propertyAddress" placeholder="请输入房产地址" />
        </el-form-item>
        <el-form-item label="购房时间" prop="propertyDate" style="width: 22%;">
          <el-date-picker clearable
            v-model="form.propertyDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择购房时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="房主" prop="propertyOwner" style="width: 22%;">
          <el-input v-model="form.propertyOwner" placeholder="请输入房主" />
        </el-form-item>
        <el-form-item label="房主身份证" prop="ownerCard" style="width: 22%;">
          <el-input v-model="form.ownerCard" placeholder="请输入房主身份证" />
        </el-form-item>
        <el-form-item label="与户主关系" prop="hukouRelate" style="width: 22%;">
          <el-input v-model="form.hukouRelate" placeholder="请输入与户主关系" />
        </el-form-item>
        <el-form-item label="与房主关系" prop="propertyRelate" style="width: 22%;">
          <el-input v-model="form.propertyRelate" placeholder="请输入与房主关系" />
        </el-form-item>
        <el-form-item label="房产证书编号" prop="propertyCode" style="width: 22%;">
          <el-input v-model="form.propertyCode" placeholder="请输入房产证书编号" />
        </el-form-item>
        <el-form-item label="迁户日期" prop="hukouDate" style="width: 22%;">
          <el-date-picker clearable
            v-model="form.hukouDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择迁户日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="邮箱" prop="email" style="width: 22%;">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="监护人" prop="chaperon" style="width: 22%;">
          <el-input v-model="form.chaperon" placeholder="请输入监护人" />
        </el-form-item>
        <el-form-item label="监护人电话" prop="chaperonPhone" style="width: 22%;">
          <el-input v-model="form.chaperonPhone" placeholder="请输入监护人电话" />
        </el-form-item>
        <el-form-item label="监护人身份证" prop="chaperonCard" style="width:22%;">
          <el-input v-model="form.chaperonCard" placeholder="请输入监护人身份证" />
        </el-form-item>
        <el-form-item label="监护人关系" prop="chaperonRelate" style="width: 22%;">
          <el-input v-model="form.chaperonRelate" placeholder="请输入监护人关系" />
        </el-form-item>
        <el-form-item label="监护人2" prop="chaperon1" style="width: 22%;">
          <el-input v-model="form.chaperon1" placeholder="请输入监护人2" />
        </el-form-item>
        <el-form-item label="监护人2电话" prop="chaperon1Phone" style="width: 22%;">
          <el-input v-model="form.chaperon1Phone" placeholder="请输入监护人2电话" />
        </el-form-item>
        <el-form-item label="监护人2身份证" prop="chaperon1Card" style="width: 22%;">
          <el-input v-model="form.chaperon1Card" placeholder="请输入监护人2身份证" />
        </el-form-item>
        <el-form-item label="监护人2关系" prop="chaperon1Relate" style="width: 22%;">
          <el-input v-model="form.chaperon1Relate" placeholder="请输入监护人2关系" />
        </el-form-item>
        <el-form-item label="退回原因" prop="reason" style="width: 22%;">
          <el-input v-model="form.reason" placeholder="请输入退回原因" />
        </el-form-item>
        <el-form-item label="备注" prop="remark" style="width: 22%;">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>
<script>
import {getContentArea } from "@/api/admin/content";
import { getSchoolArea } from "@/api/admin/school";
import { statisticsList } from "@/api/statistics/student";

export default {
  name: "Student",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学生表格数据
      studentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        areaId:null,
        enrolCode:null,
        coded:null
      },

      areaOptions:[],
      schoolAreaOptions:[],

    };
  },
  created() {
    this.getAreaFun();
    this.getList();

  },
  methods: {
    /** 查询学生列表 */
    getList() {
      this.loading = true;
      statisticsList(this.queryParams).then(response => {
        console.log('---response查询学生列表',response)
        this.studentList = response.rows;
        this.studentList.forEach(element => {

            // 处理区域
          console.log('处理区域',this.areaOptions)
          this.areaOptions.forEach(it=>{
              if(it.coded == element.areaId){
                element.areaIdStr = it.name;
              }
          })

        });
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    // cancel() {
    //   this.open = false;
    //   this.reset();
    // },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    // handleExport() {
    //   this.download('admin/student/export', {
    //     ...this.queryParams
    //   }, `student_${new Date().getTime()}.xlsx`)
    // }
    // 查看详情
    handleInfo(row){
      console.log('----查看详情',row)
    },
    // 查询区域下拉框
    getAreaFun(){
        getContentArea().then(response => {
            console.log('查询区域下拉框',response)
            if(response.code == 200){
                this.areaOptions = response.data;
            }
        });
    },
    selectSchoolArea(e){
      let areaIdStr = e.toString()
      console.log('----areaIdStr',typeof areaIdStr)
      if( this.queryParams.enrolCode){
        this.queryParams.enrolCode = null;
      }
      this.getSchoolAreaFun(areaIdStr)

    },
    getSchoolAreaFun(areaId){
      getSchoolArea(areaId).then(response => {
            console.log('查询学校数据下拉框',response)
            if(response.code == 200){
                this.schoolAreaOptions = response.data;
                // console.log('-----this.schoolList---this.schoolAreaOptions',this.schoolList)
            }
        });
     },


  }
};
</script>
